﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Compiler.CompilerAPI
{
    public class CompilationResult
    {
        private bool success = false;
        private LinkedList<string> errors = new LinkedList<string>();
        private string exceptionError = "";
        private LinkedList<string> warnings = new LinkedList<string>();
        private LinkedList<string> debugMessages = new LinkedList<string>();

        public bool Success
        {
            get { return success; }
        }

        public LinkedList<string> Errors
        {
            get { return errors; }
        }
        public bool HasErrors
        {
            get { return errors.Count > 0; }
        }
        public string ExceptionError
        {
            get { return exceptionError; }
        }

        public LinkedList<string> Warnings
        {
            get { return warnings; }
        }

        public LinkedList<string> DebugMessages
        {
            get { return debugMessages; }
        }

        public CompilationResult(bool success)
        {
            this.success = success;
        }

        public CompilationResult(bool success, string error)
        {
            this.success = success;
            AddError(error);
        }

        public void AddError(string error)
        {
            if ((error == null) || (error == ""))
                throw new ArgumentNullException("error can not be null");
            errors.AddLast(error);
        }

        public void AddWarning(string warning)
        {
            if ((warning == null) || (warning == ""))
                throw new ArgumentNullException("warning can not be null");
            warnings.AddLast(warning);
        }

        public void AddDebugMessage(string message)
        {
            if ((message == null) || (message == ""))
                throw new ArgumentNullException("message can not be null");
            debugMessages.AddLast(message);
        }

        public void SetExceptionError(string exceptionError)
        {
            if (exceptionError == null)
                throw new ArgumentNullException("exceptionError can not be null");
            this.exceptionError = exceptionError;
        }
    }
}
